/***************************************************************************/
/* NOTE:                                                                   */
/* This document is copyright (c) by Oz Solomonovich.  All non-commercial  */
/* use is allowed, as long as this document not altered in any way, and    */
/* due credit is given.                                                    */
/***************************************************************************/

// SubclassWnd.cpp : implementation file
//
// This is the base class for all subclassed windows.  It gives subclassed
// windows the ability to temporarily unsubclass themselves.

//this line was inserted and notified to you
//I remove some function or porpert which this addin do not use
//it cound not be replaced by original file

#include "stdafx.h"
#include "TabBars.h"
#include "SubclassWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSubclassWnd

//##ModelId=431C34C90020
CSubclassWnd::CSubclassWnd(HWND hWndSubclass) : 
    m_Saved_hWnd(hWndSubclass), m_bIsSubclassed(false)
{
}

//##ModelId=431C34C9004E
CSubclassWnd::~CSubclassWnd()
{
    DoUnsubclass();
}


BEGIN_MESSAGE_MAP(CSubclassWnd, CWnd)
	//{{AFX_MSG_MAP(CSubclassWnd)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CSubclassWnd message handlers


/////////////////////////////////////////////////////////////////////////////
// CSubclassWnd operations

//##ModelId=431C34C9003F
void CSubclassWnd::DoUnsubclass()
{
    // work-around for embedded windows:
    // if you open an external document (such as a WinWord file), WinWord
    // will destroy the window but our m_hWnd won't be updated
    if (!::IsWindow(m_hWnd))
    {
        m_hWnd = NULL;
        m_bIsSubclassed = false;
        return;
    }

    if (m_hWnd  &&  m_bIsSubclassed)
    {
        if (::GetWindowLong(m_hWnd, GWL_WNDPROC) == (LONG)AfxGetAfxWndProc())
        {
            UnsubclassWindow();
        }
        else
        {
            TRACE("TabBars: Trying to unsubclass a window that was "
                  "subclassed by someone else.\n");

            // someone subclassed after us (very bad!) - we'll just detach,
            // hope for the best, and keep on going...
            Detach();
        }
        m_bIsSubclassed = false;
    }
}

//##ModelId=431C34C90030
void CSubclassWnd::DoSubclass(HWND hWndSubclass /*=NULL*/)
{
    if (hWndSubclass)
    {
        m_Saved_hWnd = hWndSubclass;
    }

    if (m_Saved_hWnd  &&  !m_bIsSubclassed)
    {
        SubclassWindow(m_Saved_hWnd);
        m_bIsSubclassed = true;
    }
}
